<template>
  <div class="mult-picture">
    <div v-if="componentData.type === '1'" class="pc">
      <div v-if="componentData[`pdf${capitalizeLang}`]" class="header">
        <span>{{ componentData[`title${capitalizeLang}`] }}</span>
        <div class="btn primary" @click="showContact">
          {{ lang === 'zh' ? '立即获取报价' : 'Get a quote' }}
        </div>
        <div class="btn" @click="handleDownload(componentData[`pdf${capitalizeLang}`])">
          {{ lang === 'zh' ? '下载PDF文档' : 'Download PDF' }}
        </div>
      </div>
      <div class="detail">
        <p class="ft-60">{{ componentData[`title${capitalizeLang}`] }}</p>
        <p class="ft-32">{{ componentData[`subtitle${capitalizeLang}`] }}</p>
        <p class="ft-16">{{ componentData[`descZh${capitalizeLang}`] }}</p>
      </div>
      <img v-if="componentData.pcImgZh" :src="componentData.pcImgZh" alt="solution" />
    </div>
    <div v-if="componentData.type === '2'" class="col">
      <img
        v-for="(item, index) in componentData[`pcImg${capitalizeLang}`].split(',')"
        :key="index"
        :src="item"
        class="col-img"
        alt="solution"
      />
    </div>
    <contact-dialog-web
      v-if="contactVisible"
      :show.sync="contactVisible"
      :mode="mode"
    ></contact-dialog-web>
  </div>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
import ContactDialogWeb from '@/container/default/contact-dialog-web'

export default {
  components: {
    ContactDialogWeb,
  },
  props: {
    componentData: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      contactVisible: false,
      mode: '',
    }
  },
  computed: {
    ...mapState(['lang']),
    ...mapGetters(['capitalizeLang']),
  },
  methods: {
    handleDownload(url) {
      const name = url.split('/').pop()
      // 获取heads中的filename文件名
      const downloadElement = document.createElement('a')
      // 创建下载的链接
      downloadElement.href = url
      downloadElement.target = '_blank'
      // 下载后文件名
      downloadElement.download = name
      document.body.appendChild(downloadElement)
      // 点击下载
      downloadElement.click()
      // 下载完成移除元素
      document.body.removeChild(downloadElement)
    },
    showContact() {
      this.contactVisible = true
      this.mode = this.componentData.titleZh
    },
  },
}
</script>

<style lang="less" scoped>
@import '~assets/var';

.mult-picture {
  .pc {
    background-color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    .height(900);

    .detail {
      .mg(-40, -80, 0, 0);
      background-color: #fff;
      position: relative;

      .ft-60 {
        .ft(60);
        .lineH(100);
        color: #0762cb;
        font-weight: bold;
      }

      .ft-32 {
        .ft(32);
        .lineH(60);
        color: #444444;
        font-weight: bold;
      }

      .ft-16 {
        .ft(16);
        .lineH(32);
        color: #666666;
        font-weight: 400;
      }
    }

    img {
      .maxWidth(860);
      .maxHeight(860);
    }

    .col-img {
      width: 100%;
      height: auto;
      display: block;
    }

    .header {
      .width(1920);
      .height(72);
      .pd(0, 360, 0, 360);
      .top(100);
      position: fixed;
      z-index: 20;
      background: #fff;
      border-bottom: 1px solid #f6f4f4;
      border-top: 1px solid #f6f4f4;

      span {
        .ft(18);
        .lineH(72);
        color: #333;
        font-weight: 500;
      }

      .btn {
        .height(38);
        .ft(18);
        .lineH(36);
        .pd(0, 18, 0, 18);
        .mg(17, 0, 0, 20);
        .border(20);
        color: #0261bc;
        border: 1px solid #0261bc;
        float: right;
        cursor: pointer;

        &.primary {
          background-color: #0261bc;
          color: #fff;
        }
      }
    }
  }

  .col {
    background-color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 100px;
    .col-img {
      width: 100%;
      height: auto;
      display: block;
    }
  }
}
</style>
